local skel = fk.CreateSkill {
  name = "rmt__meimo",
}

skel:addEffect(fk.TurnStart, {
  anim_type = "negative",
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    return target ~= player and #player:getTableMark("@rmt__meimo") > 0
    and target:canUseTo(Fk:cloneCard("duel"), player)
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(target, {skill_name = skel.name, prompt = "#rmt__meimo-duel:"..player.id})
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = table.map(player:getTableMark("@rmt__meimo"), function(e) return tostring(e) end)
    local choice = tonumber(room:askToChoice(target, {choices = choices, skill_name = skel.name, prompt = "#rmt__meimo-damage"}))
    local card = Fk:cloneCard("duel")
    card.skillName = skel.name
    local use = { from = target, tos = {player}, card = card, additionalDamage = choice > 1 and choice - 1 or nil }
    room:useCard (use)
    if use.damageDealt and use.damageDealt[player] then
      room:removeTableMark(player, "@rmt__meimo", choice)
    end
  end,
})

skel:addEffect(fk.DrawNCards, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    return target == player and table.contains(player:getTableMark("@rmt__meimo"), 2)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.n = data.n + 2
  end,
})

skel:addAcquireEffect(function (self, player, is_start)
  player.room:setPlayerMark(player, "@rmt__meimo", {1, 2, 3})
end)

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@rmt__meimo", 0)
end)

skel:addEffect("atkrange", {
  correct_func = function (self, player)
    if player:hasSkill(skel.name) and table.contains(player:getTableMark("@rmt__meimo"), 3) then
      return 3
    end
  end,
})

skel:addEffect("targetmod", {
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      if player:hasSkill(skel.name) and table.contains(player:getTableMark("@rmt__meimo"), 1) then
        return 1
      end
    end
  end,
})

Fk:loadTranslationTable{
  ["rmt__meimo"] = "殙殁",
  [":rmt__meimo"] = "你的出【杀】次数上限+1，额定摸牌数+2，攻击范围+3。其他角色于回合开始时可以视为对你使用伤害基数为以上一个数值的【决斗】，对你造成伤害后，移除该数值对应句。",
  ["#rmt__meimo-duel"] = "殙殁：你可以视为对 %src 使用一张【决斗】！",
  ["#rmt__meimo-damage"] = "殙殁：选择【决斗】的伤害基数！",
  ["@rmt__meimo"] = "殙殁",

  ["$rmt__meimo1"] = "Da ogni parte m'assalgono!（他们从四面八方涌向我！）",
  ["$rmt__meimo2"] = "Ah！Chi mi masconde？（啊！谁能将我庇护！）",
}

return skel
